<?php

class omeanalysts_ome_deliveryDetailold extends eccommon_analysis_abstract implements eccommon_analysis_interface
{
    public $type_options = array(
        'display' => 'true',
    );

    public $graph_options = array(
        'hidden' => true,
    );

    public function set_params($params)
    {
        $this->_params = $params;

        return $this;
    }//End Function


    public function get_type()
    {

        #店铺
        $shopObj = app::get('ome')->model('shop');
        if($_POST['shop_ids']){
            $sql = 'SELECT shop_id,name,customername FROM sdb_ome_shop WHERE shop_id IN (\''.implode('\',\'', $_POST['shop_ids']).'\')';
            $shop_datas = kernel::database()->select($sql);
        }else{
            $shop_datas = $shopObj->getList('shop_id,name,customername',array(),0,-1);
        }
        $shop_data[0] = '全部';
        foreach ($shop_datas as $v) {
            $shop_data[$v['shop_id']] = $v['name'];

        }

        //add by ldward 20180515 改造查询
        if($_POST['shop_ids']){
            $sql = 'SELECT distinct shop_id, name, customername FROM sdb_ome_shop WHERE shop_id IN (\''.implode('\',\'', $_POST['shop_ids']).'\')';
            $shop_customer = kernel::database()->select($sql);
        }else{
            $sql = 'SELECT distinct shop_id, name, customername FROM sdb_ome_shop WHERE shop_id IN (\''.implode('\',\'', $_POST['shop_ids']).'\')';
            $shop_customer = kernel::database()->select($sql);
        }

        $shop_customers[0] = '全部';
        foreach ($shop_customer as $key => $val) {
            $shop_customers[$val['customername']] = $val['customername'];
        }
        $shop_customers = array_unique($shop_customers);

        //add by ldward 根据判断过滤权限

        $Obranch = app::get('ome')->model('branch');
        $branch_ids = $Obranch->getList('branch_id,name,uname,phone,mobile');
        $branch_data[0]='全部';
        foreach ($branch_ids as $key => $value) {
            $branch_data[$value['branch_id']]=$value['name'];
        }

        $return = array(
            'shop_id' => array(
                'lab' => '店铺',
                'data' => $shop_data,
                'type' => 'select',
            ),
            'AXCustomer' => array(
                'lab' => 'AX客户',
                'data' => $shop_customers,
                'type' => 'select',
            ),
            'branch' => array(
                'lab' => '仓库',
                'data' => $branch_data,
                'type' => 'select',
            ),
            'p_bn' => array(
                'lab' => '料品',
                'type' => 'text',
            ),
            'deliverycomp_bn' => array(
                'lab' => '发货完成单号',
                'type' => 'text',
            ),
            'customercode' => array(
                'lab' => '客户编码',
                'type' => 'text',
            ),

        );

        return $return;
    }

    public function headers()
    {
        parent::headers();
        $this->_render->pagedata['typeData'] = $this->get_type();
        $type_selected = array(
            'shop_id' => $this->_params['shop_id'],
            'AXCustomer' => $this->_params['AXCustomer'],
            'branch' => $this->_params['branch'],
            'p_bn' => $this->_params['p_bn'],
            'deliverycomp_bn' => $this->_params['deliverycomp_bn'],
            'customercode' => $this->_params['customercode'],
        );
        $this->_render->pagedata['type_selected'] = $type_selected;
    }

    public function ext_detail(&$detail)
    {
        $params = $this->_params;
        $filter = array(
            'time_from' => $params['time_from'],
            'time_to' => $params['time_to'],
        );
        if ($params['shop_id']) {
            $filter['shop_id'] = $params['shop_id'];
        }
    }

    public function finder()
    {

        $_GET['filter']['from'] = array(
            'type_id' => $_POST['type_id'],
            'p_bn' => $_POST['p_bn'],
            'time_from' => $params['time_from'],
            'time_to' => $params['time_to'],
        );

        $_extra_view = array(
            'omeanalysts' => 'ome/delivery/delivery_view.html',
        );

        $this->set_extra_view($_extra_view);

        $actions['export'] = array(
            'label' => app::get('omeanalysts')->_('生成报表<script>if($$(".finder-list").getElement("tbody").get("html") == "\n" || $$(".finder-list").getElement("tbody").get("html") == "" ){$$(".export").set("href","javascript:;").set("onclick", "alert(\"没有可以生成的数据\")");}else{$$(".export").set("href",\'index.php?app=omeanalysts&ctl=ome_delivery&act=deliveryold&action=export\');}</script>'),
            'class' => 'export',
            'icon' => 'add.gif',
            'href' => 'index.php?app=omeanalysts&ctl=ome_delivery&act=deliveryold&action=export',
            'target' => '{width:600,height:300,title:\'生成报表\'}'
        );
        $user = kernel::single('desktop_user');
        if ($user->has_permission('order_export') && $servicelist = kernel::servicelist('ietask.service.actionbar')) {
            foreach ($servicelist as $object => $instance) {
                if (method_exists($instance, 'getOmeanalystsDelivery')) {
                    $actionBars = $instance->getOmeanalystsDelivery();
                    foreach ($actionBars as $actionBar) {
                        $actions[] = $actionBar;
                    }
                }
            }
        }
        #增加报表导出权限
        $is_export = kernel::single('desktop_user')->has_permission('analysis_export');
        if (!$is_export) {
            unset($actions['export']);
        }

        $params = array(
            'actions' => $actions,
            'title' => app::get('omeanalysts')->_('发货明细表(归档)'),
            'use_buildin_recycle' => false,
            'use_buildin_selectrow' => false,
        );
        $params['op_id'] = $_POST['op_id'];

        return array(
            'model' => 'omeanalysts_mdl_ome_deliveryDetailold',
            'params' => $params,
        );
    }
}